﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ListenMusic.Song_ServiceReference;
using ListenMusic.Models.ViewModel;
using System.ServiceModel;
namespace ListenMusic.Models.Reposistory.Public
{
    public class SongReposistory
    {
        SongServiceClient songClient;
        AlbumReposistory _album;
        MusicianReposistory _musician;
        CategoryReposistory _category;
        public SongReposistory()
        {
            songClient = new SongServiceClient();
        }
        public List<View_BXH_BaiHat> getBXH_Song()
        {
            try
            {
                View_BXH_BaiHat[] bxh_Song = songClient.getBXH_BaiHat();
                return bxh_Song.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<Song> getAllSong()
        {
            try
            {
                Song[] song = songClient.getAllSong();
                return song.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<SongAlbum> getSong_byAlbumID(int albumid)
        {
            try
            {
                SongAlbum[] song = songClient.getSong_byAlbumID(albumid);
                return song.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<Song> get10Song_bySingerid(int singerid)
        {
            try
            {
                Song[] song = songClient.get10song_bySingerid(singerid);
                return song.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<SongSinger> pagingSong_bySingerid(int start, int end, int singerid)
        {
            try
            {
                SongSinger[] song = songClient.getSongbySingerID(singerid,1);
                return song.Skip(start).Take(end).ToList();
            }
            catch (FaultException e) { throw e; }
        }

        public int countSong_bySingerID(int singerid)
        {
            try
            {
                SongSinger[] song = songClient.getSongbySingerID(singerid,1);
                return song.Count();
            }
            catch (FaultException e) { throw e; }
        }

        public List<SongSinger> getRandom10Song_byCategoryID(int categoryid)
        {
            try
            {
                SongSinger[] song = songClient.getRandom10Song_byCategoryid(categoryid);
                return song.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<View20_Random_BaiBat> get20Random_Song()
        {
            try
            {
                View20_Random_BaiBat[] song = songClient.get20Random_Song();
                return song.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<ViewSearch_SongName> search_SongName(string keyword)
        {
            try
            {
                ViewSearch_SongName[] song = songClient.search_SongName(keyword);
                return song.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public int countSong_byCategoryID(int categoryid)
        {
            try
            {
                CategorySong[] song = songClient.getSongbyCategoryID(categoryid);
                return song.Count();
            }
            catch (FaultException e) { throw e; }
        }
        public List<CategorySong> paging_getSong_byCategoryID(int start, int end, int categoryid)
        {
            try
            {
                CategorySong[] song = songClient.getSongbyCategoryID(categoryid);
                return song.Skip(start).Take(end).ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<SongAlbum> getAllSonginAlbum()
        {
            try
            {
                SongAlbum[] song = songClient.getAllSongInAlbum();
                return song.ToList();
            }
            catch (FaultException e)
            {
                throw e;
            }
        }
        public List<CountrySong> getRange_Song_Video(int typeid, int countryid)
        {
            try
            {
                CountrySong[] song = songClient.getRangeSong_Video_byTypeid(typeid, countryid);
                return song.ToList();
            }
            catch (FaultException e)
            {
                throw e;
            }
        }
        public List<ListenMusic.Song_ServiceReference.Type> getAllType()
        {
            try
            {
                ListenMusic.Song_ServiceReference.Type[] type = songClient.getAllType();
                return type.ToList();
            }
            catch (FaultException e)
            {
                throw e;
            }
        }
        public List<Album_Song> getSonginAlbum(int songid)
        {
            try
            {
                Album_Song[] song = songClient.getSonginAlbum(songid);
                return song.ToList();
            }
            catch (FaultException e)
            {
                throw e;
            }
        }
        public List<SongSinger> getSong_bySongID(int songid)
        {
            try
            {
                SongSinger[] song = songClient.getSong_bySongID(songid);
                return song.ToList();
            }
            catch (FaultException e)
            {
                throw e;
            }
        }
        public Song getSong_byID(int songid)
        {
            try
            {
                Song song = songClient.getSong_byID(songid);
                return song;
            }
            catch (FaultException e)
            {
                throw e;
            } 
        }
        public bool updateCountView(int songid)
        {
            try
            {
                return songClient.updateCountView(songid);
            }
            catch (FaultException e)
            {
                return false;
                throw e;
            }
        }
        public List<SongSinger> getAllSong_bySingerID(int singerid, int typeid)
        {
            try
            {
                SongSinger[] song = songClient.getSongbySingerID(singerid,typeid);
                return song.ToList();
            }
            catch (FaultException e)
            {
              
                throw e;
            }
        }
        public List<SongSinger> getAllSong_bySingerName(int start, int end,string singerName, int typeid)
        {
            try
            {
                SongSinger[] song = songClient.getSongbySingerName(singerName,typeid);
                return song.Skip(start).Take(end).ToList();
            }
            catch (FaultException e)
            {

                throw e;
            }
        }
        public int countAllSong_bySingerName(string singerName, int typeid)
        {
            return songClient.getAllSong_bySongName(singerName, typeid).Count();
        }
        public List<SongSinger> getAllSong_bySongName(int start, int end,string songName, int typeid)
        {
            try
            {
                SongSinger[] song = songClient.getAllSong_bySongName(songName,typeid);
                return song.Skip(start).Take(end).ToList();
            }
            catch (FaultException e)
            {

                throw e;
            }
        }
        public int countAllSong_bySongName(string songName, int typeid)
        {
            return songClient.getAllSong_bySongName(songName,typeid).Count();
        }
    }
}